<template>
  <div id="officialTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" prop="auditingState">
          <el-select
            v-model="formInline.auditingState"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in auditingStateList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提交状态" prop="state">
          <el-select v-model="formInline.state" placeholder="请选择" clearable>
            <el-option
              v-for="item in stateList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上线状态" prop="activityState">
          <el-select
            v-model="formInline.activityState"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in activityStateList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询" prop="searchContent">
          <el-input
            v-model="formInline.searchContent"
            placeholder="请输入活动名称/ID查询"
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'selfTopSearch',
  msg: '官方自评征集活动-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          auditingState: '', // 审核状态,默认全部
          state: '', // 提交状态,默认全部
          activityState: '', // 上线状态
          searchContent: '', //查询内容
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 审核状态列表
      auditingStateList: [
        {
          dictLabel: '全部',
          dictValue: ''
        }
      ],
      // 提交状态列表
      stateList: [
        {
          dictLabel: '全部',
          dictValue: ''
        }
      ],
      // 上线状态列表
      activityStateList: [
        {
          dictLabel: '全部',
          dictValue: ''
        },
        {
          dictLabel: '已上线',
          dictValue: 'ONGOING'
        },
        {
          dictLabel: '已下线',
          dictValue: 'OFFLINE'
        },
        {
          dictLabel: '未上线',
          dictValue: 'NOT_STARTED'
        },
        {
          dictLabel: '已结束',
          dictValue: 'OVER'
        }
      ],
      rules: {
        auditingState: {},
        state: {},
        activityState: {},
        searchContent: {},
        createTime: { type: 'array' }
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    /* 获取字典状态 */
    async getStatusList() {
      //审核状态列表
      let data1 = await sysNormalDisable('activity_check_statu', 'checkStatu')
      this.auditingStateList = this.auditingStateList.concat(data1)
      //提交状态列表
      let data2 = await sysNormalDisable('sys_submit_status', 'submitStatu')
      this.stateList = this.stateList.concat(data2)
    }
  }
}
</script>

<style lang="less">
#officialTopSearch {
  .search-box {
    padding-left: 30px !important;
  }
  .activeType {
    width: 90px;
  }
}
</style>
